/*
 * SPDX-License-Identifier: Apache-2.0
 */

// @ts-check

const jwt = require('jsonwebtoken');
// @ts-ignore
const config = require('../explorerconfig.json');

const network_config =  require('../platform/fabric/config.json');
// @ts-check
/**
 *  The Auth Checker middleware function.
 */
module.exports = (req, res, next) => {
	for(let key  in network_config){
		for(let key2  in network_config[key]){
			if(network_config[key][key2]['name'] != undefined) {
				var network_name = network_config[key][key2]['name']
			}
		}
	}
	req.network = network_name;
	return next();
	
	// if (!req.headers.authorization) {
	// 	return res.status(401).end();
	// }
	
	
	// // Get the last part from a authorization header string like "bearer token-value"
	// const token = req.headers.authorization.split(' ')[1];
	
	// // Decode the token using a secret key-phrase
	// return jwt.verify(token, config.jwt.secret, (err, decoded) => {
	
	// 	// The 401 code is for unauthorized status
	// 	if (err) {
	// 		return res.status(401).end();
	// 	}
	// 	const userId = decoded.user;

	// 	// req.userId = userId;
	// 	req.network = decoded.network;

	// 	// TODO: check if a user exists, otherwise error

	// 	return next();
	// });
};
